const http = require('http');

const fs = require('fs');

const queryString = require('queryString');

const urlLib = require('url');

http.createServer((req,res)=>{
    //GET
    var obj = urlLib.parse(req.url,true);
    var url = obj.pathname;
    const GET = obj.query;
    //POST
    var str = '';
    var POST = {};
    req.on('data',function(data){
        str += data;
    })
    req.on('end',function(){

        POST = queryString.parse(str);
        console.log(url,GET,POST);
    })
    // url  要那个文件
    // GET  get数据
    // POST post数据

// ================ 文件请求======
    var filename = './www'+url;
    fs.readFile(filename,function(err,data){
        if(err){
            res.write('404');
        }else{
            res.write(data);
        }
        res.end();
    })
    // localhost:8080/aaa.html



}).listen(8080);
